#include <iostream>

using namespace std;

/*
 * 封装一个函数，利用冒泡排序，实现对整型数组的升序排序
 */

void bubbleSort(int arr[], int length) {
    for (int i = 0; i < length-1; ++i) {
        for (int j = 0; j < length-1-i; ++j) {
//            cout << "arr[j],arr[j+1] = " << arr[j] << "," << arr[j+1] <<endl;
            if(arr[j] > arr[j+1]) {
                int temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
}

int main() {
    int arr[] = {6,2,9,10,8,5,1,4,3,7};
    int length = sizeof(arr) / sizeof(arr[0]);
    bubbleSort(arr, length);
    for (int i = 0; i < length; ++i) {
        cout << i << " = " << arr[i] << endl;
    }
    return 0;
}
